package other;

import org.junit.Test;

/**
 * Created by lyyn on 2022/9/16.
 */
//给你单链表的头节点 head ，请你反转链表，并返回反转后的链表。
public class ReverseList_206 {
    public ListNode reverseList(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode pre = head.next;
        ListNode last = head;
        head.next = null;
        while(pre != null){
            ListNode tam = pre.next;
            pre.next = last;
            last = pre;
            pre = tam;
        }
        return last;
    }
    @Test
    public void tt(){
//        other.ListNode n4 = new other.ListNode(5);
//        other.ListNode n3 = new other.ListNode(4,n4);
//        other.ListNode n2 = new other.ListNode(3,n3);
//        other.ListNode n1 = new other.ListNode(2,n2);
//        other.ListNode head = new other.ListNode(1,n1);
        ListNode n = reverseList(new ListNode());
        while (n != null){
            System.out.println(n.val);
            n = n.next;
        }
    }
}
